package org.tawaki.free.bismuth;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class SafeEats extends Activity {
	TextView outputText;
	Button scanButton;
	
	private static final int SCAN_BARCODE = 1;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        outputText = (TextView)findViewById(R.id.TextReturn);
        scanButton = (Button)findViewById(R.id.ScanButton);
        
        scanButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				scanBarcode();
			}
		});
    }
    
    protected void scanBarcode() {
    	Intent i = new Intent("com.google.zxing.client.android.SCAN");
    	i.putExtra("SCAN_MODE", "ONE_D_MODE");
    	startActivityForResult(i, SCAN_BARCODE);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(requestCode == SCAN_BARCODE && resultCode == RESULT_OK) {
    		outputText.setText(data.getStringExtra("SCAN_RESULT"));
    	}
    }
}